package com.gwtcx.server.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public abstract class BaseDao {
	protected static String puName = "HSQLDB-HOSTED-MODE-PU";

	private static boolean initialised = false;
	private static EntityManagerFactory emf = null;

	public static EntityManager createEntityManager() {
		if (! initialised) {
			Map<String, String> props = new HashMap<String, String>();
			
			emf = Persistence.createEntityManagerFactory(puName, props);

			initialised = true;
		}

		return emf.createEntityManager();
	}

	public static void setPersistenceUnitName(String name) {
		puName= name;
	}

	public abstract Long createObject(Object object);

	public abstract List<Object> retrieveObjects(int maxResults, int firstResult);
}
